%% -*- mode: erlang;erlang-indent-level: 4;indent-tabs-mode: nil -*-
%% ex: ft=erlang ts=4 sw=4 et
[{kernel, 
    [{start_timer, true},
     {start_pg2, true}
 ]},
 {sasl, [
    {sasl_error_logger, {file, "log/emqttd_sasl.log"}}
 ]},
 {mnesia, [
    {dir, "data"}
 ]},
 {ssl, [
    %{versions, ['tlsv1.2', 'tlsv1.1']}
 ]},
 {lager, [
    {error_logger_redirect, false},
    {crash_log, "log/emqttd_crash.log"},
    {killer_hwm, 30000},
    {killer_reinstall_after, 5000},
    {handlers, [
        {lager_console_backend, error},
        {lager_file_backend, [
            {file, "log/emqttd_error.log"},
            {level, error},
            {size, 10485760},
            {date, "$D0"},
            {count, 500}
        ]},
        {lager_file_backend, [
            {file, "log/emqttd_info.log"},
            {level, info},
            {size, 10485760},
            {date, "$D0"},
            {count, 500}
        ]},
        {lager_file_backend, [
            {file, "log/emqttd_debug.log"},
            {level, debug},
            {size, 10485760},
            {date, "$D0"},
            {count, 500}
        ]}
    ]}
 ]},
 {esockd, [
    {logger, {lager, info}}
 ]},

 {mcast,
   [
        {off_servers,                   ['im_server@127.0.0.1']},
        {off_id_servers,                ['im_server@127.0.0.1']},
        {off_msg_limit,                 1000},          % 离线消息最大的长度
        {off_server_db_type,            mysql},         % 离线消息数据库类型
        {off_server_max_queue_len,      500000},        % 离线消息最大的缓冲队列长度
        {off_server_block_size,         1000},          % 离线消息每一个Block的长度
        {
            mysql_options,
            [{user, "root"}, {host,"127.0.0.1"}, {password, "rafa123"}, {database, "im_off_db"}, {keep_alive,600000}, {batch_num,13}]
        },
        {
            mysql_pooloptions, [{size, 64}, {max_overflow, 128}]   % mysql 驱动的pools配置
        },


         {mcast_max_queue_size,          1000000},     % cast 队列最大的容量
         {package_size,                  1000},        % 每次批量cast的消息量
         {force_gc,                      120000},      % 强制gc的时间间隔
         {loop_interval,                 5}            % 每次cast消息的时间间隔(ms)。
 ]},

 {emqttd, [
    
    %-% 允许每个用户最多订阅多少个主题
    {max_topic_count,  10},
    
    %-% 内存达到这个数，就不再允许登录
    {mem_no_login_rate, 70},

    %-% 内存达到这个数，将拒绝服务
    {mem_no_server_rate, 70},

    %% 是否将消息存储在log_server中，0表示不存储，1表示存储
    {msg_log_flag, 1},

    {ham_server, 'ham_server@127.0.0.1'},
    {log_server, 'log_server@127.0.0.1'},
    {packet, [
        {max_clientid_len, 1024},
        {max_packet_size, 16#ffff}
    ]},
    {client, [
        {idle_timeout, 30} %% seconds
    ]},
    {listen, [
        {mqtt, 1883, [
            {backlog, 1024},
            {acceptors, 1024},
            {max_clients, 1024000},
            {access, [{allow, all}]},
            {connopts, [{rate_limit, "100,10"}]}
            
        ]},
        {mqtts, 8883, [
            %% Size of acceptor pool
            {acceptors, 4},
            %% Maximum number of concurrent clients
            {max_clients, 512},
            %% Socket Access Control
            {access, [{allow, all}]},
            %% SSL certificate and key files
            {ssl, [{certfile, "/home/turtle/im_server/rel/files/ssl/ssl.crt"},
                   {keyfile,  "/home/turtle/im_server/rel/files/ssl/ssl.key"}]},
            %% Socket Options
            {sockopts, [
                {backlog, 1024}
                %{buffer, 4096},
            ]}
        ]},

        {http, 8088, [
            {acceptors, 1024},
            {max_clients, 1024000}
        ]},

        {https, 8089, [
            {acceptors, 1024},
            {max_clients, 1024000},
            {ssl, [{certfile, "/mnt/hgfs/work/im_server/rel/files/ssl/ssl.crt"},
                   {keyfile,  "/mnt/hgfs/work/im_server/rel/files/ssl/ssl.key"}]}
        ]}
    ]},

%    { password_check_module,   huangxin_check },
    { password_check_module,   emqttd_auth_internal},
    { password_check_callback, "http://120.77.200.228/authUser" },

    {cluster, [{ram, 'im_server@127.0.0.1',  im}]}
 ]}
].

